<template>
  <el-button type="primary" @click="handleLogin">获取token</el-button>
  <el-button type="success" @click="handleUserList">获取数据</el-button>
</template>

<script setup>
import requestUtil from '@/util/request'

const handleLogin = async () => {
  let result = await requestUtil.get("user/jwt_test")
  let data = result.data
  if (data.code === 200){
    const token = data.token
    console.log('登陆成功，token=' + token)
    window.sessionStorage.setItem('token', token)
  }
  else {
    console.log('登录出错')
  }
}

const handleUserList = async() => {
  let result = await requestUtil.get("user/test")
  let data = result.data
  if (data.code === 200){
    const userList = data.data
    console.log('用户信息列表：'+userList)
  }else {
    console.log('获取信息出错')
  }
}
</script>
